小编fis*_*g3r的帖子

不能在JavaScript中使用我的php变量

我有一个php变量.然后在按钮上点击JS,我必须打开一个包含该变量的链接.根据其他主题,这必须起作用,但事实并非如此.如果点击它就没有任何反应.

<?php
    $id = 'string';
?>
<SCRIPT language="JavaScript">
   function openBox() {
       php_var = <?php echo $id; ?>;
       targetURL = "other_page.php?id=" + php_var
       theBox = window.open(targetURL, 'theResults', 'status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=0, scrollbars=1, width=600,height=680,left=10,top=10');
   }
</SCRIPT>
Run Code Online (Sandbox Code Playgroud)

*编辑:好了,我忘了var,';.修改后的代码(如下所示)现在打开所需的站点,但var为空.如果我只是在php中回显它,它就有它的价值.

<?php
    $id = 'string';
?>
<SCRIPT language="JavaScript">
   function openBox() {
       php_var = '<?php echo $id; ?>';
       targetURL = "other_page.php?id=" + php_var
       theBox = window.open(targetURL, 'theResults', 'status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=0, scrollbars=1, width=600,height=680,left=10,top=10');
   }
</SCRIPT>
Run Code Online (Sandbox Code Playgroud)

javascript php

0
推荐指数
1
解决办法
91
查看次数

从字符串中获取多个子字符串

所以我有html文件.我需要从中提取所有链接和图像.基本上我需要:

<a href="this_is_what_I_need"><img src="this_is_also_needed">

我逐行阅读文件,可以得到它,但只有第一个:

    List<string> links = new List<string>();
    if (line.Contains(@"<a href=""") || line.Contains(@"<img src="""))
    {
        if (line.Contains(@"<a href=""")
        {
            links.Add(line.Split(new string[] { @"<a href""" }, StringSplitOptions.None)[1].Split('"')[0]);
        }
        else
        {
            links.Add(line.Split(new string[] { @"<a href=""" }, StringSplitOptions.None)[1].Split('"')[0]);
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是一行可能包含多个链接和/或图像.那么如何获得所有?

html c# string substring

0
推荐指数
1
解决办法
487
查看次数

string.substring在我的字符串上失败

我有以下代码:

string date = dtxt.Substring(5, 2) + @"/" + dtxt.Substring(7, 2) + @"/" + dtxt.Substring(0, 4);
Run Code Online (Sandbox Code Playgroud)

我试图用它解析的文本是yyyyMMdd.所以从20150309我需要03/09/2015.我不使用dateTime格式,因为输入和输出都是字符串.

问题是我得到了ArgumentOutOfRangeException.string.Substring(X, Y)应该从X索引获取子串的Y长度,不应该吗?

c# string substring

0
推荐指数
1
解决办法
82
查看次数

将新"col"添加到现有的二维数组中

我有一个二维数组:

$arr= array();
array_push($arr, array('col1' => 'someval', 'col2' => 'someval'));
array_push($arr, array('col1' => 'someval', 'col2' => 'someval'));
Run Code Online (Sandbox Code Playgroud)

现在我想为每个第二级数组添加一个新的"col" 'col3' => 'someval'.怎么做?

php arrays multidimensional-array

0
推荐指数
1
解决办法
37
查看次数

如何在输入上设置 CSS 悬停

我有这个input按钮:

<input class="btn" type="submit" id="query" name="query" value="Q" title="Query">
Run Code Online (Sandbox Code Playgroud)

这是CSS

.btn {
    cursor:pointer;
    border: none;
    background: none;
    width: 20px;
    height: 20px;
}

input.btn[type="submit"]:hover {
    border: 1px solid black;
}
Run Code Online (Sandbox Code Playgroud)

所以,正如你所看到的,hover我希望按钮有一个边框。它不起作用。我有多个按钮,这就是应用整体设置的原因class

http://jsfiddle.net/su39u2td/

html css

0
推荐指数
1
解决办法
2万
查看次数

在 Streamwriter 上设置 UTF8 编码

我需要将a的内容写入DataTablecsv。里面还有一些中文字符串。

\n\n

我曾经使用以下脚本:

\n\n
System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(dlg.FileName);\n\nstring strHeader = "";\nfor (int s = 0; s < table.Columns.Count; s++)\n{\n    strHeader += table.Columns[s].ColumnName + ",";\n}\nstreamWriter.WriteLine(strHeader);\n\nfor (int m = 0; m < table.Rows.Count; m++)\n{\n    string strRowValue = "";\n    for (int n = 0; n < table.Columns.Count; n++)\n    {\n        strRowValue += table.Rows[m][n] + ",";\n    }\n    streamWriter.WriteLine(strRowValue);\n}\nstreamWriter.Close();\n
Run Code Online (Sandbox Code Playgroud)\n\n

但这显然不能处理 Unicode 字符。它写的是类似的内容\xc3\xa6\xc5\x93\xc3\xa7\xe2\x80\xb9\xe2\x80\x94。\n所以我尝试像这样设置编码:

\n\n
System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(dlg.FileName, Encoding.UTF8);\n
Run Code Online (Sandbox Code Playgroud)\n\n

但后来我明白了Argument 1: cannot convert from \'string\' to \'System.IO.Stream。那么在这个例子中我该如何设置编码呢? …

c# encoding utf-8

-1
推荐指数
1
解决办法
1万
查看次数