我有一个点击通话功能
onclick="return qa_answer_click(16, 15, this);"
在该函数中,这将传递给变量目标,然后尝试声明以下变量:
params.code=target.form.elements.code.value;
Javascript说代码未定义。我有理由相信这是因为HTML。 this.form.elements.code会引用什么?
这是一个示例html:
<form method="post" action="../15/hur-bokf%C3%B6r-jag-n%C3%A4r-jag-k%C3%B6pt-varor-utanf%C3%B6r-eu">
<div class="qa-a-item-selected">
<div class="qa-a-item-content"> <a name="16"></a>
<div class="entry-content">
<div style="font-family: arial, sans-serif; font-size: 13px;">
<p class="p1">Välj mallen "utgift på kvitto" eller "utgift på faktura" beroende på vad som gäller.</p>
<p class="p1">Leverantören ska inte ha lagt på någon moms från sitt eget land, fyll därför i 0 i fältet moms, och hela det betalade beloppet som kostnad.</p>
</div>
<p>Tänk på att import av varor från land utanför EU ska deklareras till tullverket, som sedan fakturerar dig svensk moms och tull. <a rel="nofollow" href="http://tullverket.se/innehallao/t/tullproceduren/tullproceduren/importovergangtillfriomsattning.4.16f02a5f13c9590d97210a.html">Se information om import på tullverkets hemsida för mer information.</a>
</p>
</div>
</div> <span class="qa-a-item-avatar-meta">
<span class="qa-a-item-meta">
<a href="../15/hur-bokf%C3%B6r-jag-n%C3%A4r-jag-k%C3%B6pt-varor-utanf%C3%B6r-eu?show=16#a16" class="qa-a-item-what">besvarad</a>
<span class="qa-a-item-when">
<span class="qa-a-item-when-data"><span class="published"><span class="value-title" title="2013-11-01T09:11:19+0000"></span>1 nov</span>
</span>
</span> <span class="qa-a-item-who">
<span class="qa-a-item-who-pad">av </span>
<span class="qa-a-item-who-data"><span class="vcard author">Kristoffer Nolgren</span></span> <span class="qa-a-item-who-points">
<span class="qa-a-item-who-points-pad">(</span><span class="qa-a-item-who-points-data">3,440</span><span class="qa-a-item-who-points-pad"> poäng)</span>
</span>
</span>
<br> <span class="qa-a-item-what">ändrad</span>
<span class="qa-a-item-when">
<span class="qa-a-item-when-data"><span class="updated"><span class="value-title" title="2013-11-19T22:48:21+0000"></span>19 nov</span>
</span>
</span> <span class="qa-a-item-who">
<span class="qa-a-item-who-pad">av </span><span class="qa-a-item-who-data">Torbjörn Axelsson</span>
</span>
</span>
</span>
</div>
<div class="qa-a-item-buttons">
<input name="a16_doedit" value="ändra" title="Ändra detta svar" type="submit" class="qa-form-light-button qa-form-light-button-edit">
<input name="a16_dohide" onclick="return qa_answer_click(16, 15, this);" value="dölj" title="Dölj detta svar" type="submit" class="qa-form-light-button qa-form-light-button-hide">
<input name="a16_dofollow" value="ställ relaterad fråga" title="Ställ en ny fråga relaterad till detta svar" type="submit" class="qa-form-light-button qa-form-light-button-follow">
<input name="a16_docomment" onclick="return qa_toggle_element('c16')" value="kommentera!" title="Skriv en kommentar till det här svaret" type="submit" class="qa-form-light-button qa-form-light-button-comment">
</div>
<div class="qa-a-item-c-list" id="c16_list">
<div class="qa-c-list-item hentry comment" id="c20">
<div class="qa-c-item-content"> <a name="20"></a>
<div class="entry-content">Bra svar!!!!!!</div>
</div>
<div class="qa-c-item-footer"> <span class="qa-c-item-avatar-meta">
<span class="qa-c-item-meta">
<a href="../15/hur-bokf%C3%B6r-jag-n%C3%A4r-jag-k%C3%B6pt-varor-utanf%C3%B6r-eu?show=20#c20" class="qa-c-item-what">kommentarer</a>
<span class="qa-c-item-when">
<span class="qa-c-item-when-data"><span class="published"><span class="value-title" title="2013-11-01T15:02:12+0000"></span>1 nov</span>
</span>
</span> <span class="qa-c-item-who">
<span class="qa-c-item-who-pad">av </span>
<span class="qa-c-item-who-data"><span class="vcard author">Kristoffer Nolgren</span></span> <span class="qa-c-item-who-points">
<span class="qa-c-item-who-points-pad">(</span><span class="qa-c-item-who-points-data">150</span><span class="qa-c-item-who-points-pad"> poäng)</span>
</span>
</span>
</span>
</span>
<div class="qa-c-item-buttons">
<input name="c20_doedit" value="ändra" title="Ändra denna kommentar" type="submit" class="qa-form-light-button qa-form-light-button-edit">
<input name="c20_doflag" onclick="return qa_comment_click(20, 15, 16, this);" value="Rapportera som skräp" title="Rapportera denna kommentar som skräp eller olämplig" type="submit" class="qa-form-light-button qa-form-light-button-flag">
<input name="c20_dohide" onclick="return qa_comment_click(20, 15, 16, this);" value="dölj" title="Dölj denna kommentar" type="submit" class="qa-form-light-button qa-form-light-button-hide">
<input name="a16_docomment" onclick="return qa_toggle_element('c16')" value="svara" title="Svara på denna kommentar" type="submit" class="qa-form-light-button qa-form-light-button-comment">
</div>
</div>
<div class="qa-c-item-clear"></div>
</div>
<!-- END qa-c-item -->
<div class="qa-c-list-item hentry comment" id="c32">
<div class="qa-c-item-content"> <a name="32"></a>
<div class="entry-content">Blir det verkligen rätt med momskoder då osv? Tänker på momsdeklarationen.</div>
</div>
<div class="qa-c-item-footer"> <span class="qa-c-item-avatar-meta">
<span class="qa-c-item-meta">
<a href="../15/hur-bokf%C3%B6r-jag-n%C3%A4r-jag-k%C3%B6pt-varor-utanf%C3%B6r-eu?show=32#c32" class="qa-c-item-what">kommentarer</a>
<span class="qa-c-item-when">
<span class="qa-c-item-when-data"><span class="published"><span class="value-title" title="2013-11-12T21:23:12+0000"></span>12 nov</span>
</span>
</span> <span class="qa-c-item-who">
<span class="qa-c-item-who-pad">av </span>
<span class="qa-c-item-who-data"><span class="vcard author">Emil Jönsson</span></span> <span class="qa-c-item-who-points">
<span class="qa-c-item-who-points-pad">(</span><span class="qa-c-item-who-points-data">100</span><span class="qa-c-item-who-points-pad"> poäng)</span>
</span>
</span>
</span>
</span>
<div class="qa-c-item-buttons">
<input name="c32_doedit" value="ändra" title="Ändra denna kommentar" type="submit" class="qa-form-light-button qa-form-light-button-edit">
<input name="c32_doflag" onclick="return qa_comment_click(32, 15, 16, this);" value="Rapportera som skräp" title="Rapportera denna kommentar som skräp eller olämplig" type="submit" class="qa-form-light-button qa-form-light-button-flag">
<input name="c32_dohide" onclick="return qa_comment_click(32, 15, 16, this);" value="dölj" title="Dölj denna kommentar" type="submit" class="qa-form-light-button qa-form-light-button-hide">
<input name="a16_docomment" onclick="return qa_toggle_element('c16')" value="svara" title="Svara på denna kommentar" type="submit" class="qa-form-light-button qa-form-light-button-comment">
</div>
</div>
<div class="qa-c-item-clear"></div>
</div>
<!-- END qa-c-item -->
<div class="qa-c-list-item hentry comment" id="c37">
<div class="qa-c-item-content"> <a name="37"></a>
<div class="entry-content">Emil, för att det ska bli rätt med momsen ska du också deklarera importen till tullverket (om du inte använder en kurir som gör deklarationen åt dig). Du får sedan en faktura från tullverket på svensk moms samt eventuell tull. Denna bokför du som en vanlig utgift inom Sverige - då blir momsdeklarationen rätt!</div>
</div>
<div class="qa-c-item-footer"> <span class="qa-c-item-avatar-meta">
<span class="qa-c-item-meta">
<a href="../15/hur-bokf%C3%B6r-jag-n%C3%A4r-jag-k%C3%B6pt-varor-utanf%C3%B6r-eu?show=37#c37" class="qa-c-item-what">kommentarer</a>
<span class="qa-c-item-when">
<span class="qa-c-item-when-data"><span class="published"><span class="value-title" title="2013-11-19T22:42:59+0000"></span>19 nov</span>
</span>
</span> <span class="qa-c-item-who">
<span class="qa-c-item-who-pad">av </span>
<span class="qa-c-item-who-data"><span class="vcard author">Torbjörn Axelsson</span></span> <span class="qa-c-item-who-points">
<span class="qa-c-item-who-points-pad">(</span><span class="qa-c-item-who-points-data">1,890</span><span class="qa-c-item-who-points-pad"> poäng)</span>
</span>
</span>
</span>
</span>
<div class="qa-c-item-buttons">
<input name="c37_doedit" value="ändra" title="Ändra denna kommentar" type="submit" class="qa-form-light-button qa-form-light-button-edit">
<input name="c37_doflag" onclick="return qa_comment_click(37, 15, 16, this);" value="Rapportera som skräp" title="Rapportera denna kommentar som skräp eller olämplig" type="submit" class="qa-form-light-button qa-form-light-button-flag">
<input name="c37_dohide" onclick="return qa_comment_click(37, 15, 16, this);" value="dölj" title="Dölj denna kommentar" type="submit" class="qa-form-light-button qa-form-light-button-hide">
<input name="a16_docomment" onclick="return qa_toggle_element('c16')" value="svara" title="Svara på denna kommentar" type="submit" class="qa-form-light-button qa-form-light-button-comment">
</div>
</div>
<div class="qa-c-item-clear"></div>
</div>
<!-- END qa-c-item -->
</div>
<!-- END qa-c-list -->
</form>
答案 0 :(得分:6)
目标。 form&lt; - 对this
元素所在的表单的引用
。元素&lt; - 该形式的所有对象
。代码&lt; - 在同一code
form
的代码
undefined
的原因可能是您删除了名为code
的输入控件