Summary of common functions of JS

1. Dynamically add elements

 JS method:

<p id="demo">This is a paragraph.</p>
<button type="button" onclick="displayDate()">Display Date</button>
<script>
  function displayDate(){
      document.getElementById("demo").innerHTML=Date();
  }
</script>

 

2. The button fails

 JS method: Set the disabled property to true to be unavailable.

  页面:<input type="button" value="提交" id="btn">

document.getElementByIdx("btn").disabled=true;

 Jquery method:

$("#btn").attr("disabled", true);

 

3. Prohibit alert pop-ups 

 JS方法:window.alert = function(){ return false; }

 

 

4. innerHTML in javascript

innerHTML is a two-way function in JS: get the content of the object or insert content into the object;

For example: <div id="aa">This is the content</div>, we can get the inline content of the object whose id is aa through document.getElementById('aa').innerHTML;

You can also insert content into an object, such as document.getElementById('abc').innerHTML='This is the inserted content'; In this way, content can be inserted into the object whose id is abc 

expand:

jquery disable a tag, jquery disable button click click

jquery disable a tag method 1:

$(document).ready(function () {
        $("a").each(function () {
            var textValue = $(this).html();
            if (textValue == "XX Profile" || textValue == "Service Navigation") {
                $(this).css("cursor", "default");
                $(this).attr('href', '#'); //Modify the href attribute value of <a> to # so that the link address will not be displayed in the status bar  
                $(this).click(function (event) {
                    event.preventDefault(); // if <a> defines target="_blank" this is needed to prevent opening new pages
                });
            }
        });
});

 jquery disable a tag method 2

$('a.tooltip').live('click', function(event) {
   alert("Sorry, disabled!");  
  event.preventDefault();   
});

  jquery disable a tag method 3

$(function(){
$('.disableCss').removeAttr('href');//Remove the href attribute in the a tag
$('.disableCss').removeAttr('onclick');//Remove the onclick event in the a tag
});

 

 

Disable and enable jquery control buttons

$('#button').attr('disabled',"true");Add disabled attribute
$('#button').removeAttr("disabled"); remove the disabled attribute

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326404052&siteId=291194637