2014-04-24 36 views
-1

我使用jquerymobile 1.4.2.This对此我用我的网页代码是onchnge()函数jquerymobile工作1.4.2

<!DOCTYPE html> 
<html> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"> 
</script> 

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" /> 
    <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"> </script> 
    </head> 
    <body> 


<script> 
    function myFunction() 
    { 
    document.getElementById("myText").disabled=true; 
    } 
    </script> 

<p>Click the button to disable the text field.</p> 

<select onchange="myFunction()"><option>1</option><option>2</option></select> 

First Name: <input type="text" id="myText"> 

</body> 
</html> 

上述程序工作正常,但如果我修改成这个代码

<script> 
    function myFunction() 
    { 
    document.getElementById("myText").disabled=false; 
    } 
    </script> 
<p>Click the button to disable the text field.</p> 

<select onchange="myFunction()"><option>1</option><option>2</option></select> 

First Name: <input type="text" id="myText" disabled="disabled"> 

那么它不能正常工作,请帮助我如何使文本字段使用平变化使能()函数

回答

1

JQM增强了输入,并创建它有自己的启用/禁用方法,一个TextInput控件(http://api.jquerymobile.com/textinput/#method-disable

在你的榜样,使输入:

function myFunction() { 
    $("#myText").textinput("enable"); 
} 

此外,你应该使用非侵入式JavaScript和JQM页面的功能。例如从标记删除的onclick:

<select id="theSelect" > 
    <option>1</option> 
    <option>2</option> 
</select>First Name: 
<input type="text" id="myText" disabled="disabled" /> 

添加处理程序在pagecreate JQM事件:

function myFunction(selVal) { 
    if (selVal == '2'){ 
     $("#myText").textinput("enable"); 
    } else { 
     $("#myText").textinput("disable"); 
    } 
} 

$(document).on("pagecreate", "#page1", function() { 
    $("#theSelect").on("change", function(){ 
     var v = $(this).val(); 
     myFunction(v); 
    }); 
}); 

这里是一个DEMO

+0

是它的做工精细 – user3560322

相关问题