Javascript更改radiobutton标签的文本

时间:2015-11-17 03:55:38

标签: javascript sharepoint-2013

我有以下自动生成的单选按钮及相关标签我想从标签文本中删除文本,并且只能保留每个相应标签的以下文本 批准。 拒绝。 待定。  在下面使用javascript自动生成的HTML。 (此HTML来自SharePoint approve.aspx页面)

<table id="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus" class="ms-authoringcontrols">
	<tbody><tr>
		<td><input id="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus_0" type="radio" name="ctl00$PlaceHolderMain$approveDescription$ctl01$RadioBtnApprovalStatus" value="0" checked="checked">
                    <label for="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus_0">Approved. This item will become visible to all users.</label></td>
	</tr><tr>
		<td><input id="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus_1" type="radio" name="ctl00$PlaceHolderMain$approveDescription$ctl01$RadioBtnApprovalStatus" value="1">
                    <label for="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus_1">Rejected. This item will be returned to its creator and only be visible to its creator and all users who can see draft items.</label></td>
	</tr><tr>
		<td><input id="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus_2" type="radio" name="ctl00$PlaceHolderMain$approveDescription$ctl01$RadioBtnApprovalStatus" value="2">
                    <label for="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus_2">Pending. This item will remain visible to its creator and all users who can see draft items.</label></td>
	</tr>
</tbody></table>

1 个答案:

答案 0 :(得分:1)

您需要在“。”之后删除文本。像这样:

s = s.substring(0, s.indexOf('.'));

这是脚本:

var labels = document.getElementsByTagName('label');

for (var i in labels) {
    var text = labels[i].innerHTML;         
    if (text) labels[i].innerHTML = text.substring(0, text.indexOf('.'));
}

这是一个jsfiddle: https://jsfiddle.net/mckinleymedia/c43hjohp/1/