简体   繁体   English

用jQuery更改输入框的值

[英]changing the value of the inout box with jquery

I got a form which is being created by some class files, it only creates the classname. 我得到了一些类文件正在创建的表单,它仅创建类名。 However the background image is being set but with the value is being typed, I want to hide the background image. 但是,正在设置背景图像,但键入了值,我想隐藏背景图像。 I am trying this piece of script but it does not work: 我正在尝试这段脚本,但是它不起作用:

 <input type="text" value="" name="b_fname">

 background-image:
 url("/site/vitiscellars/images/basic_theme/your_name_bg.jpg");

This is my piece of test code: 这是我的测试代码:

javascript JavaScript的

 var $j = jQuery.noConflict();
 $j(document).ready(function() {

 $j('.b_fname').click(function() {  
     alert('Handler for called'); });     
 });

Do know why this piece of code is not working. 不知道为什么这段代码不起作用。

you have name="b_fname" but no class. 您有name =“ b_fname”但没有课程。 Add class="b_fname" or change your selector to: 添加class =“ b_fname”或将选择器更改为:

$j('[name=b_fname]')

Use class=b_fname in your html for the text box. 在HTML文本框中使用class = b_fname。

Otherwise in your jquery selector do 否则在您的jquery选择器中

$j('input[name="bfname"]') $Ĵ( '输入[名称= “bfname”]')

$j('.b_fname') selects class, not name. $j('.b_fname')选择类,而不是名称。 To get the class, you have to add the class to the input, ie <input type="text" value="" class="b_fname" name="b_fname"> . 要获取该类,您必须将该类添加到输入中,即<input type="text" value="" class="b_fname" name="b_fname">

Subsequently, you could select the element by name using $j('input[name="b_fname"]') . 随后,您可以使用$j('input[name="b_fname"]')按名称选择元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM