JQuery函数/触发器无法正常工作

时间:2017-08-22 16:06:18

标签: javascript jquery google-chrome jquery-ui safari

我尝试过使用jquery函数和触发器收音机,复选框和日期选择器。样本低于

  1. 单选按钮

    $("input[name=receivedFluStatus]:radio").change(function () {
    	reqdEntered = true;
    	//alert('radio selected');
    	if (this.id=='receivedFluOutside') {
      	alert(this.id);
    		//alert('receivedFluOutside selected');
    		//enableLocation();
    		locationEntered = false;
        	dateReceivedEntered = false;
        }
        else {
        alert(this.id);
        	//alert('receivedFluOutside not selected');
        	//disableLocation();
        	locationEntered = true;
        	dateReceivedEntered = true;
        }
    
      
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <div style='display: block;'>
                    <label>
                        <input type='radio' name='receivedFluStatus' id='receivedFluFrom'>I have received a flu vaccination
                    </label>
                </div>
        <div style='display: block;'>
                    <label>
                         <input type='radio' name='receivedFluStatus' id='receivedFluOutside'>I have received a flu vaccination
                    </label>
                </div>

  2. 复选框

  3. $("input[name=acknowledge]:checkbox").change(function() {
      //alert('acknowledge selected');
      var acknowledged = $('#acknowledge').is(':checked');
      alert(acknowledged);
    
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <div style='display: block;padding-left: 10px;'>
      <label for='acknowledge' style="font-weight: 400;">
    <input type='checkbox' name='acknowledge' id='acknowledge' value='acknowledge'> By checking this box I acknowledge
      </label>
    </div>

    1. 日期选择器
    2.  
      
         $("#outsideDate").datepicker({
      	changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        dateFormat: "mm/dd/yy",
          onSelect: function(dateText, inst) {
              console.log('date Entered'+dateText);
              dateReceivedEntered = true;
      		$('#outsideDateErrorLabel').attr('style','display:none;color: red;font-weight: 200;');
          },
          onClose: function(dateText, inst) {
          outsideDateFocus();
        }
      });
      
      function outsideDateFocus() {
      	if($('#outsideDate').val()=='MM/DD/YYYY' || $('#outsideDate').val()==''){
      		dateReceivedEntered = false;
      		$('#outsideDateErrorLabel').attr('style','display:initial;color: red;font-weight: 200;');
      	}else{
      		dateReceivedEntered = true;
      		$('#outsideDateErrorLabel').attr('style','display:none;color: red;font-weight: 200;');		
      	}
        alert(dateReceivedEntered);
      };
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
      <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js"></script>
      <div style="float:left;margin-right:20px;padding-left: 30px;">
        <label id="outsideDateLabel" for="outsideDate" style="display:block;color: lightgrey;font-weight: 400;">Date Received:</label>
        <input id="outsideDate" type="text" name="outsideDate" value="MM/DD/YYYY" style="display:block;border-style: solid;border-width: 1px;border-color: lightgrey;color: lightgrey;" readonly="readonly">
        <label id="outsideDateErrorLabel" for="outsideDate" style="display:block;color: red;font-weight: 200;">This is a required field, please enter date received</label>
      </div>

      jquery版本是1.9.1,加载类型是onLoad。所有上述工作在jsfiddle中运行得很好,我尝试了所有浏览器和所有设备。虽然上述方法不适用于负载类型头。

      但是当我在我的应用程序中添加上述函数时,这是一个在Jquery中使用ui的NodeJS应用程序,它们都不能在ios safari中工作并且间歇性地在chrome中工作

      我研究了jsfiddle如何呈现onLoad或body load类型,我也尝试了以下内容

      1. 在index.html

        上的脚本标记下添加了整个jquery脚本
         //<![CDATA[
           window.onload = function () {
         all the scripts here
          //]]>
         }
        
      2. 但接下来没有调用radio / checkbox,datepickers的处理程序

        如果我们添加head标签,处理程序会在chrome中间歇性地工作,但不会在iOS safari中工作

        任何人都可以帮我看一下

0 个答案:

没有答案