querySelector使用ng-if属性获取特定节点值

时间:2017-01-23 09:18:52

标签: javascript html

我正在搜索javascript代码以获取具有属性名称ng-if =" desc.description"的HTML标记的内容。使用javascript querySelectors。

<li ng-bind-html="esc.description" ng-if="desc.description">Hello world.</li>

3 个答案:

答案 0 :(得分:2)

使用属性选择器。

/**
 * Initializes the game's board with tiles numbered 1 through d*d - 1
 * (i.e., fills 2D array with values but does not actually print them).  
 */
void init(void)
{
    //initializing the board
    int board[d][d];
    int x = (d*d) -1;
    //this loop goes trough each row
    for(int i = 0; i < d; i++){
        //this goes trough each column
        for(int j = 0; j < d ; j++){
            //this condition handles the case of swapping the 2 and 1 when the grid is even
            if( (d % 2) == 0 && (x == 2) ){
                //assigning the number 1
                board[i][j] = x-1;

                //going to the next column
                j++;

                //assigning the number 2
                board[i][j] = x;

                //setting the x = 0 so the loop can end
                x=0;
            }
            //this happens if the above conditions are not met
            else {
                //assigning the value to the grid
                board[i][j]= x;

                //decrementing the value
                x--;
            }
            //ending the loop
            if(x == 0){
                break;
            }
        }
        //ending the loop after the last tile is initialized
        if(x == 0){
            break;
        }
    }
}
/**
 * Prints the board in its current state.
 */
void draw(void)
{
    for(int i = 0; i < d; i++){
        for(int j = 0; j < d; j++){
            if(board[i][j] != 0){
                printf("%2i", board[i][j]);
            } else {
                printf("_");
            }
        }

    printf("\n");    

    }  

答案 1 :(得分:1)

定义Id值。

HTML:

<li id="id-ex" ng-bind-html="esc.description" ng-if="desc.description">Hello world.</li>

JS:

var myInnerHtml = document.getElementById("id-ex").innerHTML;

答案 2 :(得分:1)

使用getAttribute()方法

你的元素

<script>
var a = document.getElementById('hey')
var x = a.getAttribute('ng-if') // "/"

alert(x);
</script>