5

Internet Explorer 8 と SharePoint 2007 を使用しています。

ブリーフィング: リストからのさまざまなフィールドを持つ NewForm があります。フィールドの1つからjavascriptを使用して、ユーザーが(textBoxで)導入した値を取得し、onChangeを使用して同じページの他のフィールド(他のtextBox)に貼り付ける必要があります。

問題: 私は JavaScript の初心者であり、イベント 'onChange' を設定して関数をトリガーしたり、少なくとも 'alert("Test") をトリガーしたりできません ... または単純に私のやり方が間違っていて、理由がわからない(可能性が高い)...

操作したいフィールドが FieldName="IDTeam"、type="text"、id="id_TeamField" であると仮定しましょう。

//My JS below "PlaceHolderMain"

_spBodyOnLoadFunctionNames.push("setTxtBoxesValues");

function setTxtBoxesValues()
{    
   //snipped

   getField('text','IDTeam').onChange = function(){alert('Test')}; 
   //"getField('text', 'IDTeam).onChange = function(){myFunction()};" 
   //If I want to call myFunction() when onChange event is triggered    
    }

また、 getField の代わりに、これを試しました:

document.getElementById('id_TeamField').onChange = function(){alert('Test')};

onChange イベントがトリガーされたときに myFunction() を呼び出したい場合

私が間違っていることについて何か考えはありますか?

4

4 に答える 4

10

onchange はイベントなので、次のようにタグに入れます。

<input type="text" id="IDTeam" onchange="(call function here)" />

または、addEventListener をその DOM オブジェクトに適用します。

document.getElementById("IDTeam").addEventListener("change", function() {//call function here});

IE6 では以下が必要になる場合があります:

document.getElementById("IDTeam").attachEvent("onchange", function() {//call function here} )
于 2012-06-08T17:01:22.620 に答える
2

これを行う:

window.onload = function() { 
    document.getElementById('id_TeamField').addEventListener('change', function() {
        alert('test');
    });
};

またはjQueryで:

$('#id_TeamField').on('change', function() {
    alert('test');
});
于 2012-06-08T16:44:07.873 に答える
0

あなたはこれを行うことができます

イベントリスナーの追加

document.getElementById('id_TeamField').addEventListener('change', function(){alert('test');});

また

タグに onChange を追加する

<select onChange='function() { alert('test');}' name='IDTeam' id='id_TeamField' >
   <option>option1</option>
   <option>option2</option>
   <option>option3</option>
</select>
于 2012-06-08T17:27:10.607 に答える