我有以下与Labeles相关联的Raduio按钮。
<div id="dependents">
<input ng-non-bindable type="radio" id='Partner' name="relationship" class="dependent-relation" value='P' />
<label for="Partner">Prtner</label>
<input ng-non-bindable type="radio" id='Child' name="relationship" class="dependent-relation" value='C' />
<label for="Child">Child</label>
</div>
上面的div将动态添加到页面中。我们可以有多个家属。
因此,每次附加此div时,我都会更改单选按钮的Id, name
以及for
标签。下面是我试图替换的脚本。
var html = htmlContent; // html content will be above code
html = html.replace('Partner', 'Partner' + count); // Replacing Id : Working fine
html = html.replace('for="Partner"', 'for="Partner' + count + '"'); // Replacing for : Not working
html = html.replace('Child', 'Child' + count); // Replacing Id : Working fine
html = html.replace('for="Child"', 'for="Child' + count + '"'); // Replacing for : Not working
这在IE9,IE 10,Chrome中工作得很完美,但它不能正常工作IE7和IE8。
任何人都可以帮我吗?
我发现了问题...
我想每当我试图像这样替换
html = html.replace('name="relationship"', 'name="relationship"' + count + '"');
它不起作用(仅在IE 8和7中)。任何建议???
答案 0 :(得分:0)
它不起作用的原因是因为在你替换同一个词之前。
尝试:
var html = "<div id="Dependents"> ... </div>";
html = html.replace('for="Partner"', 'for="Partner2' + count + '"');
html = html.replace('Partner', 'Partner' + count);
html = html.replace('Partner2', 'Partner');
html = html.replace('for="Child"', 'for="Child2' + count + '"');
html = html.replace('Child', 'Child' + count);
html = html.replace('Child2', 'Child');