【问题标题】:Get field from SQL Server Reporting Services Page从 SQL Server Reporting Services 页面获取字段
【发布时间】:2009-02-26 19:05:49
【问题描述】:

我正在尝试访问由 SQL Server Reporting Services 使用 JavaScript 创建的页面中的下拉框。我通常只是 getElementById 但下拉元素的 id 和 name 属性是由服务器生成的,所以我不想用它来引用元素。即如果页面的设计在未来发生变化,它会将元素命名为 _ct105 或 _ct107

我在页面上指定的唯一内容是标签“营业期间”。我正在考虑使用 xpath 来引用该跨度,然后使用下一个选择元素的相对位置,但我不知道该怎么做。

理想情况下,我可以指定 Select 元素本身的 ID 或名称(或任何其他属性)。这可能吗?

我将在页面上使用 jQuery,所以如果有人能想出一个好的方法来找到它,那就太好了。

<tr IsParameterRow="true">
<td class="ParamLabelCell">
    <span>Business Period</span>
</td>
<td class="ParamEntryCell" style="padding-right:0px;">
    <div>
        <select name="ctl140$ctl00$ctl03$ddValue" id="ctl140_ctl00_ctl03_ddValue"> <!-- This is the select box I want -->
            <option value="0">&lt;Select&nbsp;a&nbsp;Value&gt;</option>
            <option value="1">Customer</option>
            <option value="2">Previous&nbsp;Week</option>
            <option value="3">Current&nbsp;Week</option>
            <option value="4">Next&nbsp;Week</option>
        </select>
    </div>
</td>

【问题讨论】:

    标签: jquery reporting-services


    【解决方案1】:

    如果您已经在使用 jQuery,那么 XPath 将是矫枉过正。我在 jQuery 中看到了几种不同的方法来实现它。 jQuery 使用 CSS 选择器,这就是它们的工作原理:

    /* this attaches to selectboxes, which are in a div,
     * which is in a [TD] with class ParamEntryCell
     */
     $("td.ParamEntryCell div select");
     /* selects a selectbox whose id attribute starts with "ctl"
      * in an element with class ParamEntryCell 
      */
     $(".ParamEntryCell select[name^='ctl']")
     $("td.ParamEntryCell div select");
     /* selects a selectbox whose id attribute starts with "ctl"
      * in an element with class ParamEntryCell 
      */
     $(".ParamEntryCell select[id^='ctl']")
    

    然后要使用其中之一,您只需使用 jQuery 的内置方法:

    $(".ParamEntryCell select[id^='ctl']").change(function(){
        var val = $(this).val();
        alert(val);
    })
    

    【讨论】:

    • 如何将它注入到报告中?
    • 大卫,这是一段 JavaScript。这将依赖于在页面内包含 jQuery 和我的脚本,使用脚本标签和延迟执行直到 DOM 加载的机制。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-12
    • 2014-11-13
    • 1970-01-01
    相关资源
    最近更新 更多