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; } ?>cannot get string length in javascript - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

cannot get string length in javascript - Stack Overflow

programmeradmin3浏览0评论

Over 1 hour on this. This is javascript code inside my index.php file.

function dostuff()
{

   var thepath = document.location.search.substring(1);
   alert('the path is ' + thepath + " (that's the full path)");
   alert(thepath);

       // TRIED THESE ALL -- NONE OF THEM WORK.
   //var pathLen = String.length("thepath");
   //var pathLen = String.length(thepath);
   //var pathLen = thepath.length();
   var pathLen = String.length(document.location.search.substring(1));
   alert('pathLen is ' + pathLen);
}

The symptom: the first 2 alert boxes appear no problem and both show 'thepath' has a valid pathname in it, and it is the correct, expected path too.

But no matter what I try -- see the 4 different attempts, tried one at a time -- the final alert() box NEVER shows up. Why is alert('pathLen is ' + pathLen) not showing up?

(The other thing is -- I'm using XDEBUG and xampp and Netbeans and the debugger will not let me put a breakpoint in this javascript code, so I can't even step into it to see what's happening, hence the use of the alert()'s in the code. I know the XDEBUG debugger I'm using in Netbeans works -- I've been using it all night to debug PHP code in a different.PHP file. When I set a breakpoint though in any Javascript code, a 'broken breakpoint' icon appears and I cannot find what that means in Netbeans documentation.)

Over 1 hour on this. This is javascript code inside my index.php file.

function dostuff()
{

   var thepath = document.location.search.substring(1);
   alert('the path is ' + thepath + " (that's the full path)");
   alert(thepath);

       // TRIED THESE ALL -- NONE OF THEM WORK.
   //var pathLen = String.length("thepath");
   //var pathLen = String.length(thepath);
   //var pathLen = thepath.length();
   var pathLen = String.length(document.location.search.substring(1));
   alert('pathLen is ' + pathLen);
}

The symptom: the first 2 alert boxes appear no problem and both show 'thepath' has a valid pathname in it, and it is the correct, expected path too.

But no matter what I try -- see the 4 different attempts, tried one at a time -- the final alert() box NEVER shows up. Why is alert('pathLen is ' + pathLen) not showing up?

(The other thing is -- I'm using XDEBUG and xampp and Netbeans and the debugger will not let me put a breakpoint in this javascript code, so I can't even step into it to see what's happening, hence the use of the alert()'s in the code. I know the XDEBUG debugger I'm using in Netbeans works -- I've been using it all night to debug PHP code in a different.PHP file. When I set a breakpoint though in any Javascript code, a 'broken breakpoint' icon appears and I cannot find what that means in Netbeans documentation.)

Share Improve this question asked Jun 30, 2011 at 8:31 wantTheBestwantTheBest 1,7204 gold badges46 silver badges71 bronze badges 5
  • What makes you think String.length works? See: developer.mozilla/en/JavaScript/Reference/Global_Objects/… – Felix Kling Commented Jun 30, 2011 at 8:40
  • @Felix -- I based it on a sample online that used String.length() to get the length of a string in Javascript -- are you saying that the javascript String.length() function does not work or does not exist? – wantTheBest Commented Jun 30, 2011 at 8:54
  • It does not exist at all... where did you find that example? – Felix Kling Commented Jun 30, 2011 at 8:55
  • 1 No worries.... post whenever you want/can, there is no rush. In any case, www.w3schools. is not a good reference. Use MDN instead: developer.mozilla/en/JavaScript/Reference – Felix Kling Commented Jun 30, 2011 at 9:09
  • +1 @Felix, thanks for that, w3schools has helped me out, I'm such an amateur any knowledgebase is good for me, but as I've gone along these past 2 weeks, more and more I've said 'not enough info' when looking for help in w3schools -- have now bookmarked your link, thanks! – wantTheBest Commented Jun 30, 2011 at 17:09
Add a ment  | 

4 Answers 4

Reset to default 6

I've never seen that syntax before. You might want to try:

var pathLen = thepath.length;

(You'd be best off debugging with Firebug)

var pathLen = thepath.length;

Length is a property of the string, not a function, so no need for the ().

The length is a property of your string rather than a method. You should be able to access it via the following:

var pathLen = thepath.length;

When you say the alert box never shows up do you mean it never appears at all? If you're using FF you can open the error console from the Tools menu and clear it then refresh your page. It should highlight any JS errors you have in your code. That's the only reason I know of that the alert wouldn't show at all. (I don't think there is a class method for String.length() which is probably where the error is ing from.)

As for XDebug, as far as I know it's a PHP debugger only I don't think it can debug JS.

pathLen.length

No (). length is a property; if you add the (), it tries to use the value of the property as a function to call, resulting in an exception.

发布评论

评论列表(0)

  1. 暂无评论