在此代碼中,createRange
在Chrome中不起作用。在IE中它正在工作。請幫助如何糾正這一點。是否有任何其他財產像創造範圍一樣工作?這樣對我的項目會有幫助。CreateTextRange在Chrome中不起作用
<script language=javascript>
var isSelected;
function markSelection (txtObj) {
if (txtObj.createTextRange) {
txtObj.caretPos = document.selection.createRange().duplicate();
isSelected = true;
}
}
function insertTag (txtName, enclose) {
if(document.f_activity_email == null) {
var tag = document.getElementById('EmailTokenID').value;
}
else {
var formC = document.f_activity_email;
var tag = formC.EmailTokenID.value;
}
var closeTag = tag;
if (enclose) {
var attribSplit = tag.indexOf (' ');
if (tag.indexOf (' ') > -1)
closeTag = tag.substring (0, attribSplit);
}
if (isSelected) {
var txtObj = eval ("document.forms[0]." + txtName);
if (txtObj.createTextRange && txtObj.caretPos) {
var caretPos = txtObj.caretPos;
caretPos.text = ((enclose) ? "<"+tag+">"+caretPos.text+"</"+closeTag+">" : tag+caretPos.text);
markSelection (txtObj);
if (txtObj.caretPos.text=='') {
isSelected=false;
txtObj.focus();
}
}
} else {
// placeholder for loss of focus handler
}
}
*「是否有其他屬性可以像創建範圍一樣工作?」* – nnnnnn