Javascript “使用跨距文本选择”中的选项
外部系统生成翻译,并在页面上用span文本替换文本。它在大多数地方都能正常工作,但在选择中的选项不起作用。它们只支持文本。因此,我的页面有如下问题Javascript “使用跨距文本选择”中的选项,javascript,jquery,Javascript,Jquery,外部系统生成翻译,并在页面上用span文本替换文本。它在大多数地方都能正常工作,但在选择中的选项不起作用。它们只支持文本。因此,我的页面有如下问题 span class='translation'Opt1/span span class='translation'Opt2/span 我想要一些jquery/javascript函数,用文本替换选项内容并删除上面的包装器 预期结果: <select class="ProductInfo" > <option value
span class='translation'Opt1/span
span class='translation'Opt2/span
我想要一些jquery/javascript函数,用文本替换选项内容并删除上面的包装器
预期结果:
<select class="ProductInfo" >
<option value=""></option>
<option value="0">Opt1</option>
<option value="1">Opt2</option>
</select>
Opt1
Opt2
试试这个
$('.ProductNoInfo option').each(function(){
$(this).text($(this).find('span').text());
});
试试这个
$('.ProductNoInfo option').each(function(){
$(this).text($(this).find('span').text());
});
最好修复模板本身,如果不可能,您可以尝试以下方法
$('.ProductNoInfo选项').text(函数(i,t){
返回$(t).text()
});代码>
span class='translation'Opt1/span
span class='translation'Opt2/span
最好修复模板本身,如果不可能,您可以尝试以下方法
$('.ProductNoInfo选项').text(函数(i,t){
返回$(t).text()
});代码>
span class='translation'Opt1/span
span class='translation'Opt2/span
尝试使用decodeuricomponent
$(“选择选项”)。每个(函数(){
this.textContent=$(decodeURIComponent(this.textContent)).text()
})
span class='translation'Opt1/span
span class='translation'Opt2/span
尝试使用decodeuricomponent
$(“选择选项”)。每个(函数(){
this.textContent=$(decodeURIComponent(this.textContent)).text()
})
span class='translation'Opt1/span
span class='translation'Opt2/span
$(文档).ready(函数(){
$('.ProductInfo选项')。每个(函数(){
this.textContent=$(decodeURIComponent(this.textContent)).text()
});
});
span class='translation'Opt1/span
span class='translation'Opt2/span
$(文档).ready(函数(){
$('.ProductInfo选项')。每个(函数(){
this.textContent=$(decodeURIComponent(this.textContent)).text()
});
});
span class='translation'Opt1/span
span class='translation'Opt2/span
稍作解释会有所帮助。你的解决方案是什么?它是如何解决这个问题的?一点解释会很有帮助。你的解决方案是什么?它是如何解决问题的?
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function(){
$('.ProductInfo option').each(function () {
this.textContent = $(decodeURIComponent(this.textContent)).text()
});
});
</script>
</head>
<body>
<select class="ProductInfo" >
<option value=""></option>
<option value="0"><span class='translation'>Opt1</span></option>
<option value="1"><span class='translation'>Opt2</span></option>
</select>
</body>
</html>