Hello guys
, I have spent about twenty minutes searching in vain for my answer, and need your help. There are thousands of requests for help on how to select elements with jQuery - but everyone wants to do with with some kind of condition, ie, only select an anchor with a certain ID at a certain Y position on the page.
大家好,我花了大约二十分钟徒劳地寻找答案,需要你的帮助。关于如何使用jQuery选择元素有成千上万的请求帮助 - 但是每个人都想要处理某种条件,即只在页面上的某个Y位置选择具有特定ID的锚。
I have a simple request. How do I select all <span>
elements on my page and remove their text?
我有一个简单的要求。如何选择页面上的所有元素并删除其文本?
See the thing is, I have a form, and I have <spans>
. When I click the Clear Button input, all fields revert back to default (of course). But I want the span
elements to have their text deleted.
看到的是,我有一个表格,我有
The <html>
on it is simple:
它上面的很简单:
<input type="reset" value="Clear form" name="Clear Button" class="clear">
And my jQuery:
而我的jQuery:
/* Clear form - used to revert all Spans back to normal */
$('#Clear Button').click(function(){
$('span').val('');
});
So, the Reset effect works because that's DOM/HTML. But my jQuery is sadly broken.
因此,重置效果起作用,因为它是DOM / HTML。但我的jQuery很遗憾。
Can anyone tell me what's going wrong? My script is after the Button declaration, if that helps.
谁能告诉我出了什么问题?我的脚本是在Button声明之后,如果有帮助的话。
2 个解决方案
#1
12
Your problem is with your button selector. You are not selecting your button. Use this instead:
您的问题在于您的按钮选择器。你没有选择你的按钮。改为使用它:
/* Clear form - used to revert all Spans back to normal */
$('input[name="Clear Button"]').click(function(){
$('span').text('');
});
Or use $('input[type="reset"]')
if that's the only one there...
或者使用$('input [type =“reset”]')如果那是唯一一个......
#2
1
Did you source the jquery.js file into your code, and make sure when your refering to the span instead of leaving it "" (blank) use the function $('span').hide Hope i helped
您是否将jquery.js文件提取到您的代码中,并确保何时引用跨度而不是留下“”(空白)使用函数$('span')。隐藏希望我帮助
#1
12
Your problem is with your button selector. You are not selecting your button. Use this instead:
您的问题在于您的按钮选择器。你没有选择你的按钮。改为使用它:
/* Clear form - used to revert all Spans back to normal */
$('input[name="Clear Button"]').click(function(){
$('span').text('');
});
Or use $('input[type="reset"]')
if that's the only one there...
或者使用$('input [type =“reset”]')如果那是唯一一个......
#2
1
Did you source the jquery.js file into your code, and make sure when your refering to the span instead of leaving it "" (blank) use the function $('span').hide Hope i helped
您是否将jquery.js文件提取到您的代码中,并确保何时引用跨度而不是留下“”(空白)使用函数$('span')。隐藏希望我帮助