使用jquery中的onclick事件更改HTML属性值
Change HTML attribute value using onclick event in jquery
大家好,我只是想问一下如何使用jquery中的事件更改html属性值。例如,我有一个充满信息的用户列表,还有一个更新和取消按钮。用户信息是READONLY,但当用户单击按钮更新时,它将删除我的文本框中的READONLY属性。
这是我的简单代码:
<div style="display: none" id="form_edit" class="k-content">
<table border="0">
<tr>
<td>
<label>P.O. #</label>
</td>
<td>
<input type="text" name="po" value="<?php echo $order_code; ?>" readonly="readonly" />
</td>
<td>
<label>SUPPLIER NAME</label>
</td>
<td>
<input type="text" name="suppliername" value="<?php echo $sname; ?>" readonly="readonly"" />
</td>
<td>
<label>Contact Person</label>
</td>
<td>
<input type="text" name="person" value="<?php echo $contactperson; ?>" readonly="readonly" />
</td>
</tr>
<tr>
<td>
<label>TIN #</label>
</td>
<td>
<input type="text" name="tin" value="<?php echo $tin; ?>" readonly="readonly" />
</td>
</tr>
<tr>
<td colspan="6" style="text-align: right">
<input type="button" value="UPDATE" class="k-button" id="submit_form"/>
<input type="button" value="HIDE" class="k-button" id="close_form"/>
</td>
</tr>
</table>
</div>
我的jquery
$("a[name=edit_order]").click(function (e) {
$("#window_edit").data("kendoWindow").open();
e.preventDefault();
});
$("a[name=remove_order]").click(function (e) {
$("#window_remove").data("kendoWindow").open();
e.preventDefault();
});
/*here's the part that will remove the readonly attribute but how can i do that?
$("#update_supplier").click(function(){
$("#form_edit").show({
effect: "blind",
animation: 1000
});
$("#update_supplier").hide({
effect: "fade",
animation: 1000,
});
});
/*if close bring back again the readonly*/
$("#close_form").click(function(){
$("#form_edit").hide({
effect: "blind",
animation: 1000
});
$("#update_supplier").show({
effect: "fade",
animation: 1000,
});
});
尝试此代码:
$('#submit_form').on('click', function () {
$('input[name="suppliername"]').removeAttr('readonly');
});
检查我的编辑
试试这个
$('#submit_form').on('click', function () {
$('input["readonly"]').removeAttr('readonly');
});
相关文章:
- 获取HTML属性中CSS声明的值
- 如何在只接受字符串值/文字的HTML属性中调用函数
- 如何为HTML属性/选择器创建全局名称空间或变量
- 在javascript函数调用中传递的HTML属性不完整
- 如何访问自定义 HTML 属性
- AngularJS将变量绑定到自定义html属性
- 如何将 html 属性值添加到 javascript 变量中
- 为什么我不能在变量上使用内部HTML属性
- 如何将 JSON 值追加到 HTML 属性
- 使用正则表达式删除所有 html 属性(替换)
- 如何在对象中存储html属性
- 尝试更改HTML属性时出现奇怪的get请求
- 奇怪的html属性,我无法理解
- 对HTML属性进行Regex多重匹配
- JsTree从未渲染的节点获取html属性
- 基于html属性的动态jquery选择器
- jQuery未读取正确的HTML属性值
- 如何让ReactJS呈现空的HTML属性
- 将2创建的元素合并到html属性中
- 确定html属性键和值的角度指令