te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - jQuery: How can I get the HTML from inside NoScript to display in a differend div tag? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery: How can I get the HTML from inside NoScript to display in a differend div tag? - Stack Overflow

programmeradmin3浏览0评论

I've got a small script that detects if the user is using a certain browser

var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(is_chrome){
    $('.ifChrome').attr('style', 'display:block;');
    $('.ifChrome').html($('noscript > div').html());
};

If they are using this browser, we want to display a div tag and show the HTML from a different div tag inside.

<noscript>
    <div class="note">
        Your browser does not properly support the WMD Markdown Editor.<br />
        Please use <a href="/about/markdown" target="_blank">Markdown<.a> to style your input.
    </div>
</noscript>
<div class="hidden ifChrome note"></div>

What I'm trying to do is show the "not supported" text from inside my <noscript> tag to users who are using this browser (because WMD Markdown doesn't work properly with it).

My existing Javascript is not working. Any help would be greatly appreciated.

I've got a small script that detects if the user is using a certain browser

var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(is_chrome){
    $('.ifChrome').attr('style', 'display:block;');
    $('.ifChrome').html($('noscript > div').html());
};

If they are using this browser, we want to display a div tag and show the HTML from a different div tag inside.

<noscript>
    <div class="note">
        Your browser does not properly support the WMD Markdown Editor.<br />
        Please use <a href="/about/markdown" target="_blank">Markdown<.a> to style your input.
    </div>
</noscript>
<div class="hidden ifChrome note"></div>

What I'm trying to do is show the "not supported" text from inside my <noscript> tag to users who are using this browser (because WMD Markdown doesn't work properly with it).

My existing Javascript is not working. Any help would be greatly appreciated.

Share Improve this question edited Jan 2, 2011 at 5:33 Chase Florell asked Jan 1, 2011 at 22:32 Chase FlorellChase Florell 47.4k59 gold badges190 silver badges382 bronze badges 9
  • Are you sure it doesn't work in Chrome? It seems to work for me... – lonesomeday Commented Jan 1, 2011 at 22:36
  • The div shows, but the content of the noscript > div does not get displayed in the <div class="ifChrome">... Instead it's just blank. – Chase Florell Commented Jan 1, 2011 at 22:37
  • I meant that WMD Markdown seems to work. – lonesomeday Commented Jan 1, 2011 at 22:40
  • Parts of it work, parts don't. I can't get the blockquote or the lists working proper. This is a known issue because of the way the Chrome regex works. – Chase Florell Commented Jan 1, 2011 at 22:41
  • Can't you just put the same text inside the Chrome note? :)) – XCS Commented Jan 1, 2011 at 22:46
 |  Show 4 more ments

3 Answers 3

Reset to default 10

This is a bit late but you can do:

var noscriptContents = $($('noscript').html());
$('.ifChrome').append(noscriptContents);

You cannot access the content of a noscript-element using javascript in chrome. So you'll have to find a different approach that doesn't use a noscript-element. Read more about that problem here

<noscript id="noscript-main">
      <div id="div-inside-noscript">
        <span>Your content here</span>
      </div>
      <div>1</div>
      <div class="no-action">2</div>
 </noscript>
 <div id="show"></div>
<script>
      var noscript_main  = $(`#noscript-main`);
      var noscript_main_text = noscript_main.text();
      $.each($(noscript_main_text),function(k,v){
        var obj = $(v);    
        // if you want get the id of element:    
        if( obj.get(0).tagName == `DIV` ) {
          console.log( obj.prop(`id`));
        }
        //if you want display div-inside-noscript inside div#show
        if(obj.prop(`id`) == `div-inside-noscript` ){
          var obj_html = obj.html();  
          $(`#show`).html(obj_html);
        }        
      });
      //if you want remove noscript tag
      noscript_main.remove();      
 </script>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论