1

私が持っているのは、この object.innerHTML です。これは次のとおりです。

<TABLE >
 <TBODY>

  <TR>
   <TD >
      <IMG id=ctl00_Def_ctl00_ucXXXControl_gvGridName_ctl00_ctl05_imgXYZError src="etc/exclamation.png"> 
   </TD>
   <TD>
      <SELECT id=ctl00_Def_ctl00_ucXXXControl_ctl00_ctl05_rcb123 name=ctl00$Def$ctl00$ucXXXControl$gvGridName$ctl00$ctl05$rcb123>
       <OPTION value=0></OPTION> 
       <OPTION value=1>703</OPTION> 
       <OPTION value=3>704</OPTION> 
       <OPTION value=4>801</OPTION> 
       <OPTION value=5>802</OPTION> (etc)
      </SELECT> 
   </TD>
  </TR>
 </TBODY>
</TABLE>

JavaScript を介してその innerHTML テキスト blob を操作する方法を知る必要があります。select 要素の "selectedIndex" を取得するにはどうすればよいですか?

この部分が必要な場合は、より苦痛な詳細:

私は RadGrid コントロール (Telerik 製) を使用し、「インライン」編集オプションを使用しています。したがって、このグリッドには X 行が含まれ、各行には X 個のセルがあります。セルの内容が問題です。各セルには「もの」が含まれています。単純な「入力」要素などを含むものもありますが、作業する必要があるものには、2 つのセルを持つ 1 行を含むテーブル定義が含まれています。1 つのセルには画像があり、もう 1 つのセルにはドロップダウン リスト、つまり "select" 要素があります。

私の問題は、セルにドリルダウンできるように RadGrid クライアント API セットを使用したことです。この時点で、彼らはそのセルの内容を操作する方法を実際には提供していません (私が見つけることができます)。おそらく、内容は何でもかまいません。そのため、この HTML 文字列を操作する方法を理解する必要があります。jQuery と JavaScript はまだ初めてです...文字列をテーブル オブジェクトとしてキャストし、そのオブジェクトに対して jQuery セレクターを実行したいだけです...しかし、JavaScript は実際には直接動作しません...私が知る限りこれまでのところ。:(

4

2 に答える 2

0
$('#ctl00_Def_ctl00_ucXXXControl_ctl00_ctl05_rcb123').val()

選択したオプションの値を取得します。

また、id とクラスの値を html で引用符で囲みます。

于 2010-10-22T16:17:14.130 に答える
0

OK、投稿直後に思いついたアイデアは、私が使用したものになりました。これは、shoebox639 が提案したものでもあります。必要な clientID をヘルパー メソッドに引き出すコードを追加しました。

    //****************************************************************************************
//* Find a requested control's clientID as the first parm passed in from a string 
//*    passed in as the second parm. 
//****************************************************************************************
    function locateClientID(requestedClientID, HTML_StringToSearch) {
    var returnValue = "";

    //If we have something to search for and something to search in, do so.  Null or "" will fail this check.
    if (requestedClientID && HTML_StringToSearch) {

        //Find the starting point of the string starting with "id=", then any number of other letters, numbers,
        //  or underscores, then ending in the specified "requestedClientID" parm value.  We add three to offset
        //  the "id+" part of the search string, which we don't want in the results, but include to locate value.
        var startingPoint = HTML_StringToSearch.search("id=[a-z0-9A-Z_]*" + requestedClientID) + 3;

        //If we found a valid starting point, i.e. NOT -1, then continue processing the string.
        if (startingPoint > -1) {

            //Now that we know where our clientID for the requested control starts in the passed in string,
            //  find the ending " " so we know how much to substr off to pull out the requested client id.
            var endingPoint = HTML_StringToSearch.indexOf(" ", startingPoint);
            //The endingPoint could be -1 if there is no space after the "id" property, but all the examples
            //  I have seen have more attributes after.

            //substr out the clientID and return it to the caller.
            returnValue = HTML_StringToSearch.substr(startingPoint, (endingPoint - startingPoint));
         }
    }

    return returnValue;
}
//*****************************************************************************************

したがって、私の場合、rcb123 を最初のパラメーターとして渡し、innerHTML 文字列 blob を 2 番目の値として渡すと、関数は clientID 値を返します。clientID を取得したら、それを使用して別の jQuery メソッド呼び出しを実行します。

function cv123_Validate(sender, eventArgs) {

    //Get a ref to the radGrid's collection of rows.
    var gvRadGridNameRows = $find("<%= gvRadGridName.ClientID %>").MasterTableView.get_dataItems();

    var innerHTML;
    var foundClientID;
    var errorImage;
    var rcb123;

    //Process every row in the radGrid.
    for (var row = 0; row < gvRadGridNameRows.length; row++){
        //Get the cell in question's innerHTML value.
        innerHTML = gvRadGridNameRows.get_cell("uniqueCellName").innerHTML;

        //Get ref to the 'error image'.
        errorImage = $("#" + locateClientID("imgHUDError", innerHTML));

        //locate the unique clientID of the rcb123 in this row.
        foundClientID = locateClientID("rcb123", innerHTML);

        //Use the found unique clientID with jQuery to get a ref to the dropdown list.
        rcb123 = $("#" + foundClientID)[0];

        //If the dropdown list's selected index is 0 or less AND the control is NOT 
        //  disabled, active the single error message tied to this custom validator
        //  and show the 'error image' next to the control.
        if (rcb123.selectedIndex < 1 && rcb123.isDisabled != true) {
            errorImage.css("height", 12);
            eventArgs.IsValid = false;
        }
        else //Otherwise, hide the error image.
        {
            errorImage.css("height", 0);  
        }
    }
}

私はまださまざまな例をテストしており、記載されている以外の穴を探していますが、私の目的ではこれでうまくいきます。ヘルパー ルーチンを作成したのは、innerHTML ブロブでも画像を操作するためです。

アイデアは、グリッド内の各コントロールの横に「エラー画像」を配置して、エラーが発生した場所を視覚的に参照できるようにすることでしたが、単純に埋め込むときに得た X の繰り返しエラー メッセージの代わりに、1 つのエラー メッセージのみを errorSummary コントロールに追加します。ドロップダウン リストの横にある必須フィールド バリデータ。(私のBAグループはそれが気に入らなかった...)

これが誰かを助けることを願っています。

于 2010-10-26T15:10:26.747 に答える