文件问题.jQuery中的ready函数



我有一个问题与文件。jQuery jQuery函数

加载文档。Ready函数工作正常。当我点击按钮或链接时,我想重新连接文档。准备函数,我在JavaScript文件中的代码集。

下面是实际的场景。下面是JS代码示例:

$(document).ready(function() {
      var title = "This is your title";    
      var shortText = jQuery.trim(title).substring(0, 10).split(" ").slice(0, -1).join(" ") + "...";    
alert(shortText );
});

单击提交按钮后,我在下面的表行中添加输入字段数据。其中,还将描述文本添加到表的一个行列中。如果描述字段有超过100个字符,我将从外部. js文件推送上述JavaScript代码。如何刷新Java脚本功能而不刷新页面?有人知道吗?

请分享你的观点。

创建一个可以在文档中调用的函数。就绪,以及其他任何地方,例如按钮单击事件:

function myfunc(){
    var title = "This is your title";    
    var shortText = jQuery.trim(title).substring(0, 10).split(" ").slice(0, -1).join(" ") + "...";    
    alert(shortText );
}
$(document).ready(function() {
      //call  when document is ready
      myfunc();
      //call again when button is clicked
      $('#button').click(myfunc());
});

最新更新