顯示具有 jQuery 標籤的文章。 顯示所有文章
顯示具有 jQuery 標籤的文章。 顯示所有文章

2014年10月13日 星期一

[Web Form] 下拉選單jQuery塞值,後台取不到值

因為舊站台翻新

原本下拉選單要postback回後台取值方式

都改成jQuery的方式,在前台轉換


在前台submit到後台取值存檔時

<asp:Button runat="server" Text="確定送出" OnClick="submit" /> 

下拉選單

<select name="selectid" id="selectid" runat="server"></select>

在後台

string select_id = selectid.Value;

竟然是取不到值的,其實這邊我也不知道為什麼!

如果有哪位高手大大,知道的話,麻煩留言告知小弟一下,感謝!


最後解決的方式是

先建一個hidden,在下拉選單轉換時

<input type="hidden" name="hidselectid" id="hidselectid" runat="server" />
var selectid = $('#ctl00_ContentPlaceHolder1_selectid');
selectid.change(function () {
    $('#ctl00_ContentPlaceHolder1_hidselectid').val(selectid.val());
});

把值塞到hidden裡,這樣後台就可以取到hidden裡的值來用了。

2014年10月7日 星期二

jQuery 取 title ie8 error

原本很簡單的,不換頁置換title

  1.  //ie8 ok
  2.  var t_title = $("title").html();
  3.  //ie8 ok
  4.  t_title = t_title.replace("old title","new title");
  5.  //ie8 error
  6.  $("title").html(t_title);

在IE8上卻無法執行:
0x8000ffff - JavaScript 執行階段錯誤: 對方法或內容存取發出非預期的呼叫。
在下面的第四行上出現:

  1. append: function() {
  2.       return this.domManip(arguments, true, function( elem ) {
  3.              if ( this.nodeType === 1 ) {
  4. this.appendChild( elem );
  5.              }
  6.       });
  7. },

google了一下後,找到了答案

  1.  $("title").html(t_title);

置換成

  1.  $(document).attr("title", t_title);

參考:男丁格爾