2012-09-07 37 views
0

我有這種形式,當我打開我的記事本時有我的鏈接列表, 我將它從記事本複製,然後將所有鏈接粘貼到textarea那麼它應該算。jQuery。每個鏈接都包含我從textarea複製粘貼的所有鏈接

但即時嘗試解決的是,當我複製並粘貼它時,將不會自動計數,當我輸入。

我的代碼如下,以解釋我的作品。

jQuery代碼

jQuery.fn.wordCount = function(params) { 
    var p = { counterElement:"display_count" }; 
    var total_words; 

    if(params) { 
     jQuery.extend(p, params); 
    } 

    //for each keypress function on text areas 
    this.keypress(function() { 
     total_words=this.value.split("\n").length; 
     jQuery('#'+p.counterElement).html(total_words); 
    }); 
}; 

$(document).ready(function(){       
    $('#txtLinks').wordCount(); 
}); 

我的形式

<form method="post"> 
<textarea name="texturl" rows="10" cols="20" id="txtLinks" class="textarea-addlinks"></textarea> 
</form> 

並且鏈接

http://09-flex-actionscript-it.gnstudio.com/index.php?title=Are_aware_of_the_Uncomplicated_strategies_to_post_sms_to_help_all_people 
http://09-flex-actionscript-it.gnstudio.com/index.php?title=Below_To_acquire_pizza_hut_vouchers 
http://09-flex-actionscript-it.gnstudio.com/index.php?title=Brand-new_business_model_innovation_specialists 
http://09-flex-actionscript-it.gnstudio.com/index.php?title=Ery_at_times_a_good_Pizza_Express_Voucher_Are_usually_for_exciting 
http://09-flex-actionscript-it.gnstudio.com/index.php?title=Gain_knowledge_of_on_the_subject_of_signs_of_depression 
http://09-flex-actionscript-it.gnstudio.com/index.php?title=Get_yourself_a_dvd_swimming_pool_covers_currently 
http://09-flex-actionscript-it.gnstudio.com/index.php?title=Simple_and_standard_symptoms_of_the_flu 
http://09-flex-actionscript-it.gnstudio.com/index.php?title=Speaking_about_the_necessities_regarding_tinnitus_miracle: 
http://09-flex-actionscript-it.gnstudio.com/index.php?title=The_best_places_to_secure_cheap_supplements_web_based 

計數值應爲9 有什麼辦法,有沒有必要按下輸入我的意思是它會自動計算鏈接?順便說一下 - 它如何計數?它數數再見新的鏈接。

謝謝你們

+0

爲什麼不'.keyPress()'事件改變到'.change()'? – Chase

+0

'this.on('keypress paste',function(){...}' – adeneo

+0

change()正在工作謝謝你們。 – Butternut

回答

相關問題