我想要下面的代码,更改为按下按钮时,它会从下到上滚动文本区域内容.
$("button").on("click", function() {
$(document).ready(function() {
var $textarea = $('#update');
$textarea.scrollTop($textarea[0].scrollHeight);
});
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Scroll</button>
<textarea Name="update" Id="update" cols="50" rows="25"></textarea>Run Code Online (Sandbox Code Playgroud)
我有一个javascript,阻止右键单击HTML页面:
document.addEventListener("contextmenu", function(e){
e.preventDefault();
}, false);
Run Code Online (Sandbox Code Playgroud)
我<input>在同一页面上有一个标记为"链接" 的标记,我想要右键单击.
我怎样才能做到这一点?
我有一个javascript代码,可以自动在页面的任何输入字段中键入的每个句子的首字母大写。
代码如下:
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
$(document).ready(function() {
$('input').on('keydown', function(event) {
if (this.selectionStart == 0 && event.keyCode >= 65 && event.keyCode <= 90 && !(event.shiftKey) && !(event.ctrlKey) && !(event.metaKey) && !(event.altKey)) {
var $t = $(this);
event.preventDefault();
var char = String.fromCharCode(event.keyCode);
$t.val(char + $t.val().slice(this.selectionEnd));
this.setSelectionRange(1,1);
}
});
});
});//]]>
</script>
Run Code Online (Sandbox Code Playgroud)
在转换上面的代码以自动在输入字段中键入的每个单词的首字母大写而不只是仅第一个单词时,我需要帮助。
我有一个javascript,可以<div>在点击时保存as html 的内容,这在chrome上运行得很好,但在firefox上却没有.
请帮我写一个跨浏览器的解决方案.
这是我的代码:
$(window).load(function(){
function downloadInnerHtml(filename, elId, mimeType) {
var elHtml = document.getElementById(elId).innerHTML;
var link = document.createElement('a');
mimeType = mimeType || 'text/plain';
link.setAttribute('download', filename);
link.setAttribute('href', 'data:' + mimeType + ';charset=utf-8,' + encodeURIComponent(elHtml));
link.click();
}
var fileName = 'invo.html';
$('#downloadLink').click(function(){
downloadInnerHtml(fileName, 'Invoice','text/html');
});
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="Invoice">
CONTENT GOES HERE
</div>
<a href="#" onclick="return false;" id="downloadLink">Download</a>Run Code Online (Sandbox Code Playgroud)
我正在尝试使用我的 php 脚本从“counter.txt”文件中读取当前计数并添加 1 并将其保存回计数器文本文件中。
$filename = 'counter.txt';
// create the file if it doesn't exist
if (!file_exists($filename)) {
$counter_file = fopen($filename, "w");
fwrite($counter_file, "0");
$counter = 0;
} else {
$counter_file = fopen($filename, "r");
// will read the first line
$counter = fgets($counter_file);
}
// increase $counter
$counter++;
// echo counter
echo $counter;
// save the increased counter
fwrite($counter_file, "0");
// close the file
fclose($counter_file);
Run Code Online (Sandbox Code Playgroud)
脚本读取并回显数字很好,但它不会使用增加的数字保存文件。
请帮忙
我有一个 php 搜索文件,它在目录中搜索具有提交名称的文件并显示结果。我想在与 php 代码相同的文件中使用 html 表单,即在 search.php 中仅像这样:
<form action="search.php" method="get"><input name="q"
type="text"> <input type="submit"></form>
<?php
$dir = '/www/posts';
$exclude = array('.','..','.htaccess');
$q = (isset($_GET['q']))? strtolower($_GET['q']) : '';
$res = opendir($dir);
while(false!== ($file = readdir($res))) {
if(strpos(strtolower($file),$q)!== false &&!in_array($file,$exclude))
{
$last_dot_index = strrpos($file, ".");
$withoutExt = substr($file, 0, $last_dot_index);
echo "<a href='$withoutExt'>$withoutExt</a>";
echo "<br>";
}
}
closedir($res);
?>
Run Code Online (Sandbox Code Playgroud)
但上面的代码给出了错误:Warning: strpos(): Empty needle in search.php on line 10
我尝试使用!empty这样的论点:
<?php
$dir = '/www/posts';
$exclude = array('.','..','.htaccess');
$q …Run Code Online (Sandbox Code Playgroud)