Javascript 仅更改或转换单选按钮的文本,而不更改表单中的值
下面是我的代码:Javascript 仅更改或转换单选按钮的文本,而不更改表单中的值,javascript,jquery,html,forms,radio-button,Javascript,Jquery,Html,Forms,Radio Button,下面是我的代码: <form name="mainform" id="mainform" class="form_step" action="" method="post" enctype="multipart/form-data"> <ol> <li id="list_cp_ad_type"> <div class="labelwrapper"> <label> <a href="#" tip
<form name="mainform" id="mainform" class="form_step" action="" method="post" enctype="multipart/form-data">
<ol>
<li id="list_cp_ad_type">
<div class="labelwrapper">
<label>
<a href="#" tip="Choose your ad type" tabindex="999" title="Choose your ad type">
<div class="helpico"></div>
</a>Ad Type: <span class="colour">*</span>
</label>
</div>
<ol class="radios">
<li><input value="Offer Ads" type="radio" class="radiolist required" name="cp_ad_type" id="cp_ad_type"> Offer Ads</li>
<li><input value="Wanted Ads" type="radio" class="radiolist required" name="cp_ad_type" id="cp_ad_type"> Wanted Ads</li>
</ol>
<div class="clr"></div>
</li>
广告类型:*
提供广告
通缉广告
预期代码:
<form name="mainform" id="mainform" class="form_step" action="" method="post" enctype="multipart/form-data">
<ol>
<li id="list_cp_ad_type">
<div class="labelwrapper">
<label>
<a href="#" tip="Choose your ad type" tabindex="999" title="Choose your ad type">
<div class="helpico"></div>
</a>Ad Type: <span class="colour">*</span>
</label>
</div>
<ol class="radios">
<li><input value="Offer Ads" type="radio" class="radiolist required" name="cp_ad_type" id="cp_ad_type">I Offer this</li>
<li><input value="Wanted Ads" type="radio" class="radiolist required" name="cp_ad_type" id="cp_ad_type">I Want this</li>
</ol>
<div class="clr"></div>
</li>
广告类型:*
我提供这个
我想要这个
我只想将“提供广告”文本转换为“我提供此”文本,将“想要广告”文本转换为“我需要此”文本,但不转换id=“cp_ad_type”的输入值,这两个值也会对页面加载产生即时影响
有人能帮我吗?试试看
jQuery(function(){
$('.radios input:radio[value="Offer Ads"]').get(0).nextSibling.data = 'I offer this'
$('.radios input:radio[value="Wanted Ads"]').get(0).nextSibling.data = 'I Want this'
})
演示:我假设您正在使用您标记的内容。这可能对你有用
$('input:radio[value="Offer Ads"]').parent().text('I Offer this');
$('input:radio[value="Wanted Ads"]').parent().text('I Want this');
不过,我建议对每个元素使用不同的名称,否则它将不是有效的HTML。引用W3C文档:
文档中不能有多个具有相同属性的元素
id值
ID应该是唯一的,为每个单选按钮分配唯一的ID,或者改用类 试试这个
function change()
{
document.getElementById('cp_ad_type').setAttribute('value',"your value");
}
ID必须是唯一的。对不起,你的问题不是很清楚。您希望如何通过jQuery更改文本?你是什么意思:“这对页面加载也有直接影响”?