使用jQuery prev()和next()查找正确的SPAN标记

时间:2015-04-28 19:13:52

标签: javascript jquery html

嘿所有我需要以下html代码才能获得“提供最佳微笑”的价值,这似乎是 6 prev() 2 Next ()

gyp ERR! configure error
gyp ERR! stack Error: spawn C:\tools\pyhton2 ENOENT
gyp ERR! stack     at exports._errnoException (util.js:746:11)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1046:32)
gyp ERR! stack     at child_process.js:1137:20
gyp ERR! stack     at process._tickCallback (node.js:355:11)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\test\node_modules\xsl-transform\node_modules\node_xslt
gyp ERR! node -v v0.12.1
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "xsl-transform"
npm ERR! node v0.12.1
npm ERR! npm  v2.5.1
npm ERR! code ELIFECYCLE

npm ERR! node_xslt@0.1.9 preinstall: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node_xslt@0.1.9 preinstall script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the node_xslt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls node_xslt
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\test\npm-debug.log

我当时的位置是输入标记的达到并保持质量值。

目前我尝试了以下内容:

<div id="eea305a4-32b2-434d-8623-4dc3e2fcf119F_SelectMany" class="lfFormField
     lfFormFieldSelectMany  F_Form1-P_NewPage-F_SelectMany">
  <div class="">
    <fieldset class="composite-field-fieldset">
      <legend class="no-form-field-mandatory-sign-css">
        <span id="F_SelectMany-required"
              class="form-field-mandatory-sign-css lfFormFieldRequiredMarker no-form-field-mandatory-sign-css">*</span>
        <span class="form-field-title-sign-css lfFormLabel">deliver best smile</span>
      </legend>
      <div style="padding=left:0.1em" 
           dojoattachevent="onmouseover:onMouseOver, onclick:onClick, onmouseout:onMouseOut" 
           class="dojoDndHandle freedom-base-mixin-css" 
           id="eea305a4-32b2-434d-8623-4dc3e2fcf119F_SelectMany-widget" 
           widgetid="eea305a4-32b2-434d-8623-4dc3e2fcf119F_SelectMany-widget">
        <ul id="e2b7488e-a88c-4da0-8287-4f8e4e6091f4tbl" 
            dojoattachpoint="containerNode,focusNode" 
            class="selection-group">
          <li dojoattachpoint="listItem" 
              class="vertical-selection-group-item" 
              id="freedom_widget_solution_form_FreedomOptionButton_0" 
              value="0" type="checkbox"
              widgetid="freedom_widget_solution_form_FreedomOptionButton_0">
            <div class="selection-group-item-container notDojoDndHandle">
              <span dojoattachevent="onmouseover:onMouseOver, onclick:onClick, onmouseout:onMouseOut" 
                    class="selection-group-item-input dijitInline freedom-base-mixin-css freedom-base-mixin-cssChecked dijitChecked" 
                    widgetid="2ff949f4-c88e-4769-8e36-23c81661af92-btn">
                <input dojoattachpoint="textbox,focusNode,_aroundNode" 
                       id="2ff949f4-c88e-4769-8e36-23c81661af92-btn" 
                       class="dijitReset dijitCheckBox notDojoDndHandle" 
                       type="checkbox" tabindex="0" 
                       dojoattachevent="onclick:_onClick" 
                       role="checkbox" aria-checked="true" 
                       name="group_eea305a4-32b2-434d-8623-4dc3e2fcf119F_SelectMany-widget" 
                       value="Achieve and maintain quality" 
                       style="-webkit-user-select: none;">    
              </span>
              <div class="selection-group-item-text-container dijitInline">
                <label dojoattachpoint="titleNode" 
                       for="2ff949f4-c88e-4769-8e36-23c81661af92-btn" 
                       class="selection-group-item-text bold-selection-group-item">Achieve and maintain quality</label>
              </div>
            </div>
          </li>

var testing 是我试图从中获取该值但却出现“未定义”所以我猜我没有停在正确的位置?

任何帮助都会很棒!

3 个答案:

答案 0 :(得分:5)

您可以尝试遍历父容器,然后通过它的类对该元素进行查找。

例如:

通过id遍历父级:

$(this).closest('#eea305a4-32b2-434d-8623-4dc3e2fcf119F_SelectMany').find('.form-field-title-sign-css');

按类遍历父级:

$(this).closest('.lfFormField').find('.form-field-title-sign-css');

或通过HTML元素遍历父级:

$(this).closest('fieldset').find('.form-field-title-sign-css');

要获得该值,在这种情况下,您可能希望.text()而不是.html()。当然,除非你真的想要所有的HTML。

最后,如果此ID F_SelectMany-required不是随机的。你可以这样做。这应该有助于它更具体一点。

$(this).closest('.lfFormField').find('#F_SelectMany-required').children('.form-field-title-sign-css');

答案 1 :(得分:0)

检查此代码

$(function(){
    var $lbl=$("label[dojoattachpoint='titleNode']");    //Your position
    $lbl.click(function(){
        if (!$("#" + $(this).attr("for")).is(":checked")) {
            var $fieldset=$(this).closest("fieldset");
            alert($("legend",$fieldset).find("span").text());    
        }
    })    
})

答案 2 :(得分:0)

Jquery的prev()为您提供之前的兄弟。在您发布的文档的DOM中,值中的“达到并保持质量”的输入没有任何兄弟姐妹。它是围绕它的跨度的唯一孩子,所以无论你使用prev()和next()的组合,你都将得到未定义。你的意思是使用parent()而不是prev()吗? 但更好的是给那个跨度一个id          带来最好的笑容 并使用$(“#SmileSpanId”)

来实现它