Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> JavaScript

JavaScript में "हाँ" और "नहीं" विकल्पों के साथ डायलॉग कैसे बनाएं?


मानक कन्फर्मेशन बॉक्स की सीमा

नहीं, आप "हाँ" या "नहीं" के साथ डायलॉग बॉक्स नहीं बना सकते। JavaScript में एक कन्फर्मेशन डायलॉग बॉक्स में "Ok" और "Cancel" बटन होते हैं।

"हाँ" या "नहीं" के साथ डायलॉग बनाने के लिए, कस्टम डायलॉग बॉक्स का उपयोग करें।

उदाहरण: jQuery के साथ कस्टम डायलॉग

<!DOCTYPE html> <html> 
  <head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
    <script> 
      function functionConfirm(msg, myYes, myNo) { 
        var confirmBox = $("#confirm"); 
        confirmBox.find(".message").text(msg); 
        confirmBox.find(".yes,.no").unbind().click(function() { 
          confirmBox.hide(); 
        }); 
        confirmBox.find(".yes").click(myYes); 
        confirmBox.find(".no").click(myNo); 
        confirmBox.show(); 
      } 
    </script> 
    <style> 
      #confirm { 
        display: none; 
        background-color: #91FF00; 
        border: 1px solid #aaa; 
        position: fixed; 
        width: 250px; 
        left: 50%; 
        margin-left: -100px; 
        padding: 6px 8px 8px; 
        box-sizing: border-box; 
        text-align: center; 
      } 
      #confirm button { 
        background-color: #48E5DA; 
        display: inline-block; 
        border-radius: 5px; 
        border: 1px solid #aaa; 
        padding: 5px; 
        text-align: center; 
        width: 80px; 
        cursor: pointer; 
      } 
      #confirm .message { 
        text-align: left; 
      } 
    </style> 
  </head> 
  <body> 
    <div id="confirm"> 
      <div class="message"></div> 
      <button class="yes">Yes</button> 
      <button class="no">No</button> 
    </div> 
    <button onclick = 'functionConfirm("Do you like Football?", function yes() { 
      alert("Yes") 
    }, 
    function no() { 
      alert("no") 
    });'>submit</button> 
  </body> 
</html>
  1. HTML और JavaScript से वजन कन्वर्टर कैसे बनाएं? HTML और JavaScript से वजन कन्वर्टर कैसे बनाएं?

    HTML और JavaScript से वजन कन्वर्टर बनाने के लिए कोड निम्न है -उदाहरण<!DOCTYPE html> <html> <head> <style>    body{       font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;    }    input,span{      

  1. Android में Neutral ऑप्शन के साथ डायलॉग कैसे बनाएं? Android में Neutral ऑप्शन के साथ डायलॉग कैसे बनाएं?

    उद्देश्य यह उदाहरण दर्शाता है कि Android में Neutral ऑप्शन (Yes, No, Cancel) के साथ डायलॉग कैसे बनाएं। चरण 1: नया प्रोजेक्ट बनाएं Android Studio में File → New Project पर जाएं और नया प्रोजेक्ट बनाने के लिए सभी आवश्यक विवरण भरें। चरण 2: लेआउट XML जोड़ें निम्न कोड को res/layout/activity_main.xml मे

  1. CSS और JavaScript से एकॉर्डियन कैसे बनाएं CSS और JavaScript से एकॉर्डियन कैसे बनाएं

    CSS और JavaScript से एकॉर्डियन बनाने के लिए, कोड निम्नलिखित है:उदाहरण<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> .demo { background-color: #eee; cursor: pointer; padding: 25px; width: 100