我正在研究一个聪明的模板,该模板只能编辑HTML并仅放置JavaScript,但不能编辑php代码。
该列表如下所示:
<select>
<option id="1" value="first">{$line1}</option>
<option id="2" value="second">{$line2}</option>
</select>
在实时页面中,
{$line1}
显示为green
,而{$line2}
显示为black and white
。我想放置一个JavaScript或jQuery代码以从()中删除(删除)
and white
文本,以便仅显示{$line2}
。有什么建议?您的回答将不胜感激。 最佳答案
这是一个动态解决方案:
$('select option').each(function(i, item){
var words = $(item).text().split(' ');
$(item).text(words[0]);
});
演示:Fiddle