0

我正在使用 rsform pro 并希望我的客户可以轻松地将停电日期添加到 javascript 日历中。我创建了一个文本输入框,它将用户输入传输到文本区域。这是我到目前为止所拥有的:

function transfer() {
    var x = document.getElementById("txtT").value;
    document.getElementById("JS").value += '\n' + 'if(param1.indexOf(\'' + x + '\') === 0) \n\{ \n alert("We are almost booked up for this day.  Please call xxx-xxx-xxxx to make reservations."); \n return false; \n\}\n'
};

这是文本区域的内容

<script type="text/javascript">
function rsfp_onSelectDate(param1)
    {
if(param1.indexOf('Sunday') === 0)
{
    alert("Sorry.  We are closed on Sundays & Mondays.");
    return false;
}
    if(param1.indexOf('Monday') === 0)
{
    alert("Sorry.  We are closed on Sundays & Mondays.");
    return false;
}    
else return true;
}
</script>

我想要做的是 onClick 在其他返回 true 之前将其转移到该行。

这可能吗?

4

1 回答 1

0

见小提琴

function transfer() {
    var x = document.getElementById("txtT").value;
    var textarea = document.getElementById("JS");
    var toappend = '\n' + 'if(param1.indexOf(\'' + x + '\') === 0) \n\{ \n alert("We are almost booked up for this day.  Please call xxx-xxx-xxxx to make reservations."); \n return false; \n\}\n';
    var reg = /(?=else return true)/;
    var oldtext = textarea.value;
    var arr = oldtext.split(reg);
    var newtext = arr[0] + toappend + arr[1];
    textarea.value = newtext
};
于 2013-06-14T03:28:24.017 回答