如何使用jQuery设置动态文本框的只读属性? [英] How to set readonly property of dynamic textbox using jQuery?
本文介绍了如何使用jQuery设置动态文本框的只读属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从DB值填充文本框,我想要只读取文本框值。当用户单击编辑选项时,则将所有文本框设置为可编辑。我未能实现这一目标。这是我的HTML代码:
I'm trying to fill a textbox from DB values and I want to set textbox value readonly. When the user clicks on an EDIT option then set all textboxes become editable. I have failed to achieve this. Here is my HTML code:
<html>
<head>
<script>
$(document).ready(function() {
$('#contentid :input').each(function() {
$(this).attr("disabled",true);
});
$('#edit').on('click',function() {
$('#contentid :input').each(function() {
$(this).attr('disabled',false);});
});
});
</script>
</head>
<body>
<div data-role="page" id="viewInformation" data-theme="d" data-add-back-btn="true" data-back-btn-text = "back">
<div data-role="header" id="headerid" class="ui-bar ui-bar-b">
<h3></h3>
</div>
<div data-role="content" id="contentid">
<a href="#" id="saveDBValue" data-role="button" data-mini="true" style="width:60px; height:40px; float:center;">SAVE</a>
<a href="#" id="edit" data-role="button">EDIT</a>
</div>
</div>
</body>
这是我的JavaScript代码:
Here is my JavaScript code:
function getDataofSelectedListItem()
{
alert("getDataofSelectedListI");
clickedListItem = window.localStorage.getItem("clickedValueofList");
console.log("clicked list item"+clickedListItem);
//db = window.openDatabase("loginintro", "1.0", "loginintro", 1000000);
var sqlQuery = 'SELECT * FROM loginTable WHERE username=\''+window.localStorage.getItem("clickedValueofList").trim()+'\';';
console.log("selected list query:"+sqlQuery);
db.transaction(function(tx)
{
tx.executeSql(sqlQuery,[],successCBofListItem,errorCBofListItem);
},errorCB,successCB);
}
function successCBofListItem(tx,results)
{ alert("erer");
if(results != null && results.rows != null && results.rows.length > 0)
{ $('#contentid').append('<label>UserName:</label><input content-editable="false" id="name" type="text" value="'+results.rows.item(0).username+'"/>');
$('#contentid').append('<label>EMAIL ID:</label><input type="text" value="'+results.rows.item(0).emailid+'"/>');
$('#contentid').append('<label>Password:</label><input type="text" value="'+results.rows.item(0).password+'"/>');
}
function errorCBofListItem()
{
alert("errorCBofListItem");
}
我做错了什么?
推荐答案
你必须使用live来捕获点击事件
You have to use live for capturing the click event
$('#edit').live('click',function()
我创建了一个< a href =http://jsfiddle.net/UhXe4/>示例
这篇关于如何使用jQuery设置动态文本框的只读属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文