在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:NicolasCARPi/jquery_jeditable开源软件地址:https://github.com/NicolasCARPi/jquery_jeditable开源编程语言:JavaScript 96.4%开源软件介绍:jquery-jeditableDEPRECATION NOTICEThis project is deprecated and should not be used in a fresh project. Have a look at Malle library instead. It is more or less the same, but in typescript and without a jQuery dependency. Alternative libraryUse Malle. DescriptionEdit in place plugin for jQuery (compatible with jQuery v3.4.0+). Bind it to an element on the page, and when clicked the element will become a form that will be sent by asynchronous (ajax) POST request to an URL. Works with text inputs, textarea, select, datepicker, and more… Comes with a ton of different options you can use to do exactly what you want! Live demoSee it in action: LIVE DEMO Installationnpm install jquery-jeditable UsageLoading the libraryUse a Most basic usageThere is only one mandatory parameter. URL where browser sends edited content. $(document).ready(function() {
$('.edit').editable('save.php');
}); Code above does several things: Elements with class Not bad for oneliner, huh? Let's add some options. Adding options$(document).ready(function() {
$('.edit').editable('save.php', {
indicator : 'Saving…',
event : 'dbclick',
cssclass : 'custom-css',
submit : 'Save',
tooltip : 'Double click to edit…'
});
$('.edit_area').editable('save.php', {
type : 'textarea',
cancel : 'Cancel',
submit : 'OK',
indicator : '<img src="img/spinner.svg" />',
tooltip : 'Click to edit…'
});
$('.edit_select').editable('save.php', {
type : 'select',
indicator : 'Saving ...',
loadurl : 'api/load.php',
inputcssclass : 'form-control',
cssclass : 'form'
});
}); In the code above, the elements of class The elements of class The elements of class Both elements will have a tooltip showing when mouse is hovering. The live demo shows more example but with that you can already do plenty! The complete list of options is available here: FULL LIST OF OPTIONS What is sent to the server?When the user clicks the submit button a POST request is sent to the target URL like this: id=element_id&value=user_edited_content Where If you'd like to change the names of the parameters sent, you need to add two options: $('.edit').editable('save.php', {
id : 'bookId',
name : 'bookTitle'
}); And the code above will result in this being sent to the server: bookId=element_id&bookTitle=user_edited_content Loading dataIf you need to load a different content than the one displayed (element is from a Wiki or is in Markdown or Textile and you need to load the source), you can do so with the $('.edit_area').editable('save.php', {
loadurl : 'load.php',
loadtype : 'POST',
loadtext : 'Loading…',
type : 'textarea',
submit : 'OK'
}); By default it will do a GET request to The PHP script And save.php should return the html (because this is what is displayed to the user after submit). Or you can pass the source in the I like writing sentences (and finishing them with text in parenthesis). Using selectsYou can use selects by giving type parameter value of select. Select is built from JSON encoded array. This array can be given using either JSON encoded array looks like this: {"E":"Letter E","F":"Letter F","G":"Letter G", "selected":"F"} Note the last entry. It is special. With value of $('.editable-select').editable('save.php', {
data : '{"E":"Letter E","F":"Letter F","G":"Letter G", "selected":"F"}',
type : 'select',
submit : 'OK'
}); What if you need to generate values for pulldown dynamically? Then you can fetch values from external URL. Let's assume we have the following PHP script: <?php // json.php
$array['E'] = 'Letter E';
$array['F'] = 'Letter F';
$array['G'] = 'Letter G';
$array['selected'] = 'F';
echo json_encode($array); Then instead of $('.editable-select').editable('save.php', {
loadurl : 'json.php',
type : 'select',
submit : 'OK'
}); Styling elementsYou can style input element with $('.editable').editable('save.php', {
cssclass : 'someclass'
});
$('.editable').editable('save.php', {
loadurl : 'json.php',
type : 'select',
submit : 'OK',
style : 'display: inline'
}); Both parameters can have special value of Following example will make the word oranges editable with a pulldown menu. This pulldown inherits style from I love eating <span class="editable" style="display: inline">oranges</span>. $('.editable').editable('save.php', {
loadurl : 'json.php',
type : 'select',
submit : 'OK',
style : 'inherit'
}); Submitting to function instead of URLSome people want to control absolutely everything. I want to keep you happy. You can get full control of Ajax request. Just submit to function instead of URL. Parameters passed are same as with callback. $('.editable').editable(function(value, settings) {
console.log(this);
console.log(value);
console.log(settings);
return(value);
}, {
type : 'textarea',
submit : 'OK',
}); Note that the function must return a string. Usually the edited content. This will be displayed on the page after editing. Other optionsThe demo contains other examples, have a look! The complete list of options is available here: FULL LIST OF OPTIONS SupportPlease open a GitHub issue if you have a bug to report, a question to ask or if you just want to discuss something related to the project. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论