jquery复制insertafter

时间:2016-12-13 04:31:13

标签: jquery insertafter

这段代码在visualforce页面(salesforce)上加载脚本添加日期的页面,每次单击复选框时它再次运行脚本并复制超链接

我需要帮助来编写一个关于如何避免生成重复的hylerlinks的代码。



<script>
var j$ = jQuery.noConflict();

j$(document).ready(function() {
    replaceDate();           
});
   
function replaceDate(){
    j$(apptDate).next().hide();
    j$('<span class="dateFormat">[&nbsp;<a href="javascript:setPlus(3, apptDate, resDate);">+3 days</a>&nbsp;]</span>').insertAfter(j$(apptDate));


    j$(fdDate).next().hide();
    j$('<span class="dateFormat" id="fdDate_7">[&nbsp;<a class="plusDate" href="javascript:setPlus(7, fdDate, apptDate);">+7 days</a>&nbsp;]</span>').insertAfter(j$(fdDate));
    j$('<span class="dateFormat" id="fdDate_14">[&nbsp;<a class="plusDate" href="javascript:setPlus(14, fdDate, apptDate);">+14 days</a>&nbsp;]</span>').insertAfter(j$(fdDate_7));
    j$('<span class="dateFormat" id="fdDate_21">[&nbsp;<a class="plusDate" href="javascript:setPlus(21, fdDate, apptDate);">+21 days</a>&nbsp;]</span>').insertAfter(j$(fdDate_14));
    j$('<span class="dateFormat" id="fdDate_28">[&nbsp;<a class="plusDate" href="javascript:setPlus(28, fdDate, apptDate);">+28 days</a>&nbsp;]</span>').insertAfter(j$(fdDate_21));

    j$(soilTestDate).next().hide();
    j$('<span class="dateFormat" id="soilTestDate_7">[&nbsp;<a class="plusDate" href="javascript:setPlus(7, soilTestDate, apptDate);">+7 days</a>&nbsp;]</span>').insertAfter(j$(soilTestDate));
    j$('<span class="dateFormat" id="soilTestDate_14">[&nbsp;<a class="plusDate" href="javascript:setPlus(14, soilTestDate, apptDate);">+14 days</a>&nbsp;]</span>').insertAfter(j$(soilTestDate_7));
    j$('<span class="dateFormat" id="soilTestDate_21">[&nbsp;<a class="plusDate" href="javascript:setPlus(21, soilTestDate, apptDate);">+21 days</a>&nbsp;]</span>').insertAfter(j$(soilTestDate_14));
    j$('<span class="dateFormat" id="soilDate_28">[&nbsp;<a class="plusDate" href="javascript:setPlus(28, soilTestDate, apptDate);">+28 days</a>&nbsp;]</span>').insertAfter(j$(soilTestDate_21));
    
    j$(salePropertyDate).next().hide();
    j$('<span class="dateFormat" id="salePropertyDate_7">[&nbsp;<a class="plusDate" href="javascript:setPlus(7, salePropertyDate, apptDate);">+7 days</a>&nbsp;]</span>').insertAfter(j$(salePropertyDate));
    j$('<span class="dateFormat" id="salePropertyDate_14">[&nbsp;<a class="plusDate" href="javascript:setPlus(14, salePropertyDate, apptDate);">+14 days</a>&nbsp;]</span>').insertAfter(j$(salePropertyDate_7));
    j$('<span class="dateFormat" id="salePropertyDate_21">[&nbsp;<a class="plusDate" href="javascript:setPlus(21, salePropertyDate, apptDate);">+21 days</a>&nbsp;]</span>').insertAfter(j$(salePropertyDate_14));
    j$('<span class="dateFormat" id="salePropertyDate_28">[&nbsp;<a class="plusDate" href="javascript:setPlus(28, salePropertyDate, apptDate);">+28 days</a>&nbsp;]</span>').insertAfter(j$(salePropertyDate_21));
    
    j$(firbDueDate).next().hide();
    j$('<span class="dateFormat" id="firbDueDate_7">[&nbsp;<a class="plusDate" href="javascript:setPlus(7, firbDueDate, apptDate);">+7 days</a>&nbsp;]</span>').insertAfter(j$(firbDueDate));
    j$('<span class="dateFormat" id="firbDueDate_14">[&nbsp;<a class="plusDate" href="javascript:setPlus(14, firbDueDate, apptDate);">+14 days</a>&nbsp;]</span>').insertAfter(j$(firbDueDate_7));
    j$('<span class="dateFormat" id="firbDueDate_21">[&nbsp;<a class="plusDate" href="javascript:setPlus(21, firbDueDate, apptDate);">+21 days</a>&nbsp;]</span>').insertAfter(j$(firbDueDate_14));
    j$('<span class="dateFormat" id="firbDueDate_28">[&nbsp;<a class="plusDate" href="javascript:setPlus(28, firbDueDate, apptDate);">+28 days</a>&nbsp;]</span>').insertAfter(j$(firbDueDate_21));
    
    j$(otherDate).next().hide();
    j$('<span class="dateFormat" id="otherDate_7">[&nbsp;<a class="plusDate" href="javascript:setPlus(7, otherDate, apptDate);">+7 days</a>&nbsp;]</span>').insertAfter(j$(otherDate));
    j$('<span class="dateFormat" id="otherDate_14">[&nbsp;<a class="plusDate" href="javascript:setPlus(14, otherDate, apptDate);">+14 days</a>&nbsp;]</span>').insertAfter(j$(otherDate_7));
    j$('<span class="dateFormat" id="otherDate_21">[&nbsp;<a class="plusDate" href="javascript:setPlus(21, otherDate, apptDate);">+21 days</a>&nbsp;]</span>').insertAfter(j$(otherDate_14));
    j$('<span class="dateFormat" id="otherDate_28">[&nbsp;<a class="plusDate" href="javascript:setPlus(28, otherDate, apptDate);">+28 days</a>&nbsp;]</span>').insertAfter(j$(otherDate_21));
    
}
&#13;
<input type="checkbox" onclick="replaceDate()"
&#13;
&#13;
&#13;

0 个答案:

没有答案