问题描述
我正在建立的这个网站中有一个反馈系统,要求用户为他们所收到的服务提供反馈.他们可以选择提供实际反馈,也可以跳过整个过程.我有2个单选按钮(其中1个为肯定按钮;另一个为否定按钮)
I have a feedback system in this website I'm building and users are asked to provide feedback for the service they've received. They have a choice to either provide an actual feedback or skip the entire thing. I have 2 radio buttons (1 for positive; the other negative)
<input type="radio" name="rating" value="1" id="green" /><label for="green">Positive</label><br />
<input type="radio" name="rating" value="0" id="red" /><label for="red">Negative</label>
然后,我有一个textarea
供用户提供实际反馈.
Then, I have a textarea
for users to provide the actual feedback.
<textarea style="width: 95%;" rows="6" name="feedback"></textarea>
如果用户点击实际的单选按钮,我宁愿仅启用文本区域.如果不是,则文本区域保持禁用状态.我应该怎么做呢? (我在考虑jQuery)
I'd rather have the textarea enabled ONLY if the user clicks on an actual radio button. If not, the textarea remains disabled. How should I go about this? (I'm thinking jQuery)
谢谢,伙计们.
谢谢大家的快速输入.另外,如果我可以添加的话,如果我说要从MySQL中的数据生成行,那该怎么办.这使得名称(即,对于用户ID 1)为name = rating [1]和name = feedback [1].如何使用jQuery选择它们?
Thanks for the quick input, guys. Also, if I may add, what if let's say I'm generating the rows from data in MySQL. Which makes the names (ie. for userid 1) name=rating[1] and name=feedback[1]. How do I select them using jQuery?
推荐答案
$('input[name="rating"]').on('change', function() {
$('textarea[name="feedback"]').show();
});
根据您的评论进行更新:
Update according to your comment:
$('input[name="rating"]').on('change', function() {
$('textarea[name="feedback"]').attr('disabled', false).focus();
});
这篇关于使仅当单选按钮被选中一个textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!