jQuery更改输入文本值 [英] jQuery change input text value

查看:64
本文介绍了jQuery更改输入文本值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到合适的选择器:

I can't find the right selector for:

<input maxlength="6" size="6" id="colorpickerField1" name="sitebg" value="#EEEEEE" type="text">

我想将值更改为=000000.我需要选择器来查找名称"而不是文本输入的ID.

I want to change the value to = 000000. I need the selector to find the "name" not the id of the text input.

这不行吗?:

$("text.sitebg").val("000000");

提出的解决方案不起作用,这是什么问题?

The presented solution does not work, what's the problem with this?

$.getJSON("http://www.mysitehere.org/wp-content/themes/ctr-theme/update_genform.php",function(data) {
    $("#form1").append(data.sitebg);
    $('input.sitebg').val('000000');
});

JSON数据正常工作;想法是稍后将JSON值传递到表单输入文本值中.但不起作用:(

The JSON data is working correctly; the idea is to later pass the JSON values into the form input text values. But is not working :(

推荐答案

否,您需要执行以下操作:

no, you need to do something like:

$('input.sitebg').val('000000');

但是如果可以的话,您实际上应该使用唯一的ID.

but you should really be using unique IDs if you can.

您还可以获取更具体的信息,例如:

You can also get more specific, such as:

$('input[type=text].sitebg').val('000000');

执行此操作以根据名称属性查找您的输入:

do this to find your input based on the name attribute:

$('input[name=sitebg]').val('000000');

这篇关于jQuery更改输入文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆